/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ipartek.formacion.gestformwww.modelo.clases;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Aitor/Victor
 * Metodo que cotrola si recibe un null en numero y si es asi pasa un 0.
 */
public class SentenciaNula {

    private PreparedStatement stmt;

    public SentenciaNula(Connection con, String sql){
        try {
            stmt = con.prepareStatement(sql);
        } catch (SQLException ex) {
            Logger.getLogger(SentenciaNula.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public SentenciaNula(Connection con, String sql, int opcion) {
        try {
            stmt = con.prepareStatement(sql, opcion);
        } catch (SQLException ex) {
            Logger.getLogger(SentenciaNula.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void setInt(int columna, Integer valor) throws SQLException {
        if (valor == null) {
            stmt.setNull(columna, java.sql.Types.INTEGER);
        } else {
            stmt.setInt(columna, valor);
        }
    }

    public void setString(int columna, String valor) throws SQLException {
        if (valor == null) {
            stmt.setNull(columna, java.sql.Types.VARCHAR);
        } else {
            stmt.setString(columna, valor);
        }
    }

    public void setBoolean(int columna, Boolean valor) throws SQLException {
        if (valor == null) {
            stmt.setNull(columna, java.sql.Types.BIT);
        } else {
            stmt.setBoolean(columna, valor);
        }
    }

    public void setTimestamp(int columna, Timestamp valor) throws SQLException {
        if (valor == null) {
            stmt.setNull(columna, java.sql.Types.TIMESTAMP);
        } else {
            stmt.setTimestamp(columna, valor);
        }
    }

    public int executeUpdate() throws SQLException {
        return stmt.executeUpdate();
    }

    public ResultSet executeQuery() throws SQLException {
        return stmt.executeQuery();
    }

    public ResultSet getGeneratedKeys() throws SQLException {
        return stmt.getGeneratedKeys();
    }

    public void close() throws SQLException {
        stmt.close();
    }
}
